/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Board.java
 *
 * Created on 10-mar-2010, 23.10.37
 */

package giocodel15;
import func.func;
import javax.swing.JOptionPane;

/**
 *
 * @author paolo
 */
public class Board extends javax.swing.JFrame {
    private int mosse;
    private time t;

    private class time extends Thread{
        private long time;

        public time(){
            this.time=func.time();
        }

        @Override
        public void run() {
            while(true){
                long secondo= func.time();
                long tempo= secondo-this.time;
                String stamp=func.FormattaTempo(tempo);
                jLabel19.setText(stamp);
            }
        }


    }
    

    /** Creates new form Board */
    public Board() {
        initComponents();
        this.mosse=0;
        this.t= new time();
    }

    public void shuffle(){
        String[] tasti={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15",""};
        String[] testi=new String[16];
        int num=0;
        int[] usciti={16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16};
        for(int i=0; i<16; i++){
        int rand=func.rand(15);
        while(func.isNumInArray(rand, usciti)){
            rand=func.rand(15);
        }
        testi[i]=tasti[rand];
        usciti[num]=rand;
        num++;
        }
        this.jLabel1.setText(testi[0]);
        this.jLabel2.setText(testi[1]);
        this.jLabel3.setText(testi[2]);
        this.jLabel4.setText(testi[3]);
        this.jLabel5.setText(testi[4]);
        this.jLabel6.setText(testi[5]);
        this.jLabel7.setText(testi[6]);
        this.jLabel8.setText(testi[7]);
        this.jLabel9.setText(testi[8]);
        this.jLabel10.setText(testi[9]);
        this.jLabel11.setText(testi[10]);
        this.jLabel12.setText(testi[11]);
        this.jLabel13.setText(testi[12]);
        this.jLabel14.setText(testi[13]);
        this.jLabel15.setText(testi[14]);
        this.jLabel16.setText(testi[15]);
        this.jLabel17.setText("Mosse: 0");
        this.mosse=0;
        this.t.start();
    }

    public void reset(){
        this.jLabel1.setText("1");
        this.jLabel2.setText("2");
        this.jLabel3.setText("3");
        this.jLabel4.setText("4");
        this.jLabel5.setText("5");
        this.jLabel6.setText("6");
        this.jLabel7.setText("7");
        this.jLabel8.setText("8");
        this.jLabel9.setText("9");
        this.jLabel10.setText("10");
        this.jLabel11.setText("11");
        this.jLabel12.setText("12");
        this.jLabel13.setText("13");
        this.jLabel14.setText("14");
        this.jLabel15.setText("15");
        this.jLabel16.setText("");
        this.jLabel17.setText("Mosse: 0");
        this.mosse=0;
    }

    public void impossibile(){
        JOptionPane.showMessageDialog(rootPane, "Attenzione: questa versione del gioco è ancora irrisolta\nse riesci a risolverla sei un vero mostro!");
        this.jLabel1.setText("1");
        this.jLabel2.setText("2");
        this.jLabel3.setText("3");
        this.jLabel4.setText("4");
        this.jLabel5.setText("5");
        this.jLabel6.setText("6");
        this.jLabel7.setText("7");
        this.jLabel8.setText("8");
        this.jLabel9.setText("9");
        this.jLabel10.setText("10");
        this.jLabel11.setText("11");
        this.jLabel12.setText("12");
        this.jLabel13.setText("13");
        this.jLabel14.setText("15");
        this.jLabel15.setText("14");
        this.jLabel16.setText("");
        this.jLabel17.setText("Mosse: 0");
        this.mosse=0;
        this.t.start();
    }

    public void winner(){
        this.mosse++;
        this.jLabel17.setText("Mosse: "+this.mosse);
        if(this.jLabel1.getText().equals("1") && this.jLabel2.getText().equals("2") && this.jLabel3.getText().equals("3") && this.jLabel4.getText().equals("4") && this.jLabel5.getText().equals("5") && this.jLabel6.getText().equals("6") && this.jLabel7.getText().equals("7") && this.jLabel8.getText().equals("8") && this.jLabel9.getText().equals("9") && this.jLabel10.getText().equals("10") && this.jLabel11.getText().equals("11") && this.jLabel12.getText().equals("12") && this.jLabel13.getText().equals("13") && this.jLabel14.getText().equals("14") && this.jLabel15.getText().equals("15") && this.jLabel16.getText().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Complimenti!! Hai vinto il Gioco del 15 in "+this.mosse+" mosse!");
        }
        this.t.stop();
        this.t= new time();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(231, 158, 36));
        jPanel1.setLayout(new java.awt.GridLayout(4, 4));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("1");
        jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel1);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("2");
        jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel2);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("3");
        jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel3);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("4");
        jLabel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel4MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel4);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("5");
        jLabel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel5MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel5);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("6");
        jLabel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel6MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel6);

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("7");
        jLabel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel7);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("8");
        jLabel8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel8MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel8);

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("9");
        jLabel9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel9);

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("10");
        jLabel10.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel10MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel10);

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("11");
        jLabel11.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel11MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel11);

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("12");
        jLabel12.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel12MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel12);

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("13");
        jLabel13.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel13MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel13);

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("14");
        jLabel14.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel14MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel14);

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("15");
        jLabel15.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel15MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel15);

        jLabel16.setBackground(java.awt.Color.white);
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabel16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel16MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel16);

        jButton1.setText("Nuovo Gioco");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Reset");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Impossibile");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel17.setText("Mosse: 0");

        jLabel18.setText("Tempo trascorso:");

        jLabel19.setText("0:00:00");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(189, 189, 189)
                .addComponent(jLabel17)
                .addContainerGap(197, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel19)
                .addContainerGap(155, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton3)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.shuffle();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        if(this.jLabel2.getText().equals("")){
            String swap=this.jLabel1.getText();
            this.jLabel1.setText(this.jLabel2.getText());
            this.jLabel2.setText(swap);
            this.winner();
        }else if(this.jLabel5.getText().equals("")){
            String swap=this.jLabel1.getText();
            this.jLabel1.setText(this.jLabel5.getText());
            this.jLabel5.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel1MouseClicked

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
        if(this.jLabel1.getText().equals("")){
            String swap=this.jLabel2.getText();
            this.jLabel2.setText(this.jLabel1.getText());
            this.jLabel1.setText(swap);
            this.winner();
        }else if(this.jLabel6.getText().equals("")){
            String swap=this.jLabel2.getText();
            this.jLabel2.setText(this.jLabel6.getText());
            this.jLabel6.setText(swap);
            this.winner();
        }else if(this.jLabel3.getText().equals("")){
            String swap=this.jLabel2.getText();
            this.jLabel2.setText(this.jLabel3.getText());
            this.jLabel3.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel2MouseClicked

    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked
        if(this.jLabel2.getText().equals("")){
            String swap=this.jLabel3.getText();
            this.jLabel3.setText(this.jLabel2.getText());
            this.jLabel2.setText(swap);
            this.winner();
        }else if(this.jLabel7.getText().equals("")){
            String swap=this.jLabel3.getText();
            this.jLabel3.setText(this.jLabel7.getText());
            this.jLabel7.setText(swap);
            this.winner();
        }else if(this.jLabel4.getText().equals("")){
            String swap=this.jLabel3.getText();
            this.jLabel3.setText(this.jLabel4.getText());
            this.jLabel4.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel3MouseClicked

    private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked
        if(this.jLabel3.getText().equals("")){
            String swap=this.jLabel4.getText();
            this.jLabel4.setText(this.jLabel3.getText());
            this.jLabel3.setText(swap);
            this.winner();
        }else if(this.jLabel8.getText().equals("")){
            String swap=this.jLabel4.getText();
            this.jLabel4.setText(this.jLabel8.getText());
            this.jLabel8.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel4MouseClicked

    private void jLabel5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseClicked
        if(this.jLabel1.getText().equals("")){
            String swap=this.jLabel5.getText();
            this.jLabel5.setText(this.jLabel1.getText());
            this.jLabel1.setText(swap);
            this.winner();
        }else if(this.jLabel6.getText().equals("")){
            String swap=this.jLabel5.getText();
            this.jLabel5.setText(this.jLabel6.getText());
            this.jLabel6.setText(swap);
            this.winner();
        }else if(this.jLabel9.getText().equals("")){
            String swap=this.jLabel5.getText();
            this.jLabel5.setText(this.jLabel9.getText());
            this.jLabel9.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel5MouseClicked

    private void jLabel6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseClicked
        if(this.jLabel5.getText().equals("")){
            String swap=this.jLabel6.getText();
            this.jLabel6.setText(this.jLabel5.getText());
            this.jLabel5.setText(swap);
            this.winner();
        }else if(this.jLabel2.getText().equals("")){
            String swap=this.jLabel6.getText();
            this.jLabel6.setText(this.jLabel2.getText());
            this.jLabel2.setText(swap);
            this.winner();
        }else if(this.jLabel7.getText().equals("")){
            String swap=this.jLabel6.getText();
            this.jLabel6.setText(this.jLabel7.getText());
            this.jLabel7.setText(swap);
            this.winner();
        }else if(this.jLabel10.getText().equals("")){
            String swap= this.jLabel6.getText();
            this.jLabel6.setText(this.jLabel10.getText());
            this.jLabel10.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel6MouseClicked

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
        if(this.jLabel6.getText().equals("")){
            String swap=this.jLabel7.getText();
            this.jLabel7.setText(this.jLabel6.getText());
            this.jLabel6.setText(swap);
            this.winner();
        }else if(this.jLabel3.getText().equals("")){
            String swap=this.jLabel7.getText();
            this.jLabel7.setText(this.jLabel3.getText());
            this.jLabel3.setText(swap);
            this.winner();
        }else if(this.jLabel8.getText().equals("")){
            String swap=this.jLabel7.getText();
            this.jLabel7.setText(this.jLabel8.getText());
            this.jLabel8.setText(swap);
            this.winner();
        }else if(this.jLabel11.getText().equals("")){
            String swap= this.jLabel7.getText();
            this.jLabel7.setText(this.jLabel11.getText());
            this.jLabel11.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked
        if(this.jLabel4.getText().equals("")){
            String swap=this.jLabel8.getText();
            this.jLabel8.setText(this.jLabel4.getText());
            this.jLabel4.setText(swap);
            this.winner();
        }else if(this.jLabel7.getText().equals("")){
            String swap=this.jLabel8.getText();
            this.jLabel8.setText(this.jLabel7.getText());
            this.jLabel7.setText(swap);
            this.winner();
        }else if(this.jLabel12.getText().equals("")){
            String swap=this.jLabel8.getText();
            this.jLabel8.setText(this.jLabel12.getText());
            this.jLabel12.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel8MouseClicked

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        if(this.jLabel5.getText().equals("")){
            String swap=this.jLabel9.getText();
            this.jLabel9.setText(this.jLabel5.getText());
            this.jLabel5.setText(swap);
            this.winner();
        }else if(this.jLabel10.getText().equals("")){
            String swap=this.jLabel9.getText();
            this.jLabel9.setText(this.jLabel10.getText());
            this.jLabel10.setText(swap);
            this.winner();
        }else if(this.jLabel13.getText().equals("")){
            String swap=this.jLabel9.getText();
            this.jLabel9.setText(this.jLabel13.getText());
            this.jLabel13.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel9MouseClicked

    private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel10MouseClicked
        if(this.jLabel6.getText().equals("")){
            String swap=this.jLabel10.getText();
            this.jLabel10.setText(this.jLabel6.getText());
            this.jLabel6.setText(swap);
            this.winner();
        }else if(this.jLabel9.getText().equals("")){
            String swap=this.jLabel10.getText();
            this.jLabel10.setText(this.jLabel9.getText());
            this.jLabel9.setText(swap);
            this.winner();
        }else if(this.jLabel11.getText().equals("")){
            String swap=this.jLabel10.getText();
            this.jLabel10.setText(this.jLabel11.getText());
            this.jLabel11.setText(swap);
            this.winner();
        }else if(this.jLabel14.getText().equals("")){
            String swap= this.jLabel10.getText();
            this.jLabel10.setText(this.jLabel14.getText());
            this.jLabel14.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel10MouseClicked

    private void jLabel11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MouseClicked
        if(this.jLabel7.getText().equals("")){
            String swap=this.jLabel11.getText();
            this.jLabel11.setText(this.jLabel7.getText());
            this.jLabel7.setText(swap);
            this.winner();
        }else if(this.jLabel10.getText().equals("")){
            String swap=this.jLabel11.getText();
            this.jLabel11.setText(this.jLabel10.getText());
            this.jLabel10.setText(swap);
            this.winner();
        }else if(this.jLabel12.getText().equals("")){
            String swap=this.jLabel11.getText();
            this.jLabel11.setText(this.jLabel12.getText());
            this.jLabel12.setText(swap);
            this.winner();
        }else if(this.jLabel15.getText().equals("")){
            String swap= this.jLabel11.getText();
            this.jLabel11.setText(this.jLabel15.getText());
            this.jLabel15.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel11MouseClicked

    private void jLabel12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseClicked
        if(this.jLabel8.getText().equals("")){
            String swap=this.jLabel12.getText();
            this.jLabel12.setText(this.jLabel8.getText());
            this.jLabel8.setText(swap);
            this.winner();
        }else if(this.jLabel11.getText().equals("")){
            String swap=this.jLabel12.getText();
            this.jLabel12.setText(this.jLabel11.getText());
            this.jLabel11.setText(swap);
            this.winner();
        }else if(this.jLabel16.getText().equals("")){
            String swap= this.jLabel12.getText();
            this.jLabel12.setText(this.jLabel16.getText());
            this.jLabel16.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel12MouseClicked

    private void jLabel13MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel13MouseClicked
        if(this.jLabel9.getText().equals("")){
            String swap=this.jLabel13.getText();
            this.jLabel13.setText(this.jLabel9.getText());
            this.jLabel9.setText(swap);
            this.winner();
        }else if(this.jLabel14.getText().equals("")){
            String swap=this.jLabel13.getText();
            this.jLabel13.setText(this.jLabel14.getText());
            this.jLabel14.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel13MouseClicked

    private void jLabel14MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel14MouseClicked
        if(this.jLabel10.getText().equals("")){
            String swap=this.jLabel14.getText();
            this.jLabel14.setText(this.jLabel10.getText());
            this.jLabel10.setText(swap);
            this.winner();
        }else if(this.jLabel13.getText().equals("")){
            String swap=this.jLabel14.getText();
            this.jLabel14.setText(this.jLabel13.getText());
            this.jLabel13.setText(swap);
            this.winner();
        }else if(this.jLabel15.getText().equals("")){
            String swap=this.jLabel14.getText();
            this.jLabel14.setText(this.jLabel15.getText());
            this.jLabel15.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel14MouseClicked

    private void jLabel15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel15MouseClicked
        if(this.jLabel11.getText().equals("")){
            String swap=this.jLabel15.getText();
            this.jLabel15.setText(this.jLabel11.getText());
            this.jLabel11.setText(swap);
            this.winner();
        }else if(this.jLabel14.getText().equals("")){
            String swap=this.jLabel15.getText();
            this.jLabel15.setText(this.jLabel14.getText());
            this.jLabel14.setText(swap);
            this.winner();
        }else if(this.jLabel16.getText().equals("")){
            String swap=this.jLabel15.getText();
            this.jLabel15.setText(this.jLabel16.getText());
            this.jLabel16.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel15MouseClicked

    private void jLabel16MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel16MouseClicked
        if(this.jLabel12.getText().equals("")){
            String swap=this.jLabel16.getText();
            this.jLabel16.setText(this.jLabel12.getText());
            this.jLabel12.setText(swap);
            this.winner();
        }else if(this.jLabel15.getText().equals("")){
            String swap=this.jLabel16.getText();
            this.jLabel16.setText(this.jLabel15.getText());
            this.jLabel15.setText(swap);
            this.winner();
        }
    }//GEN-LAST:event_jLabel16MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.reset();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.impossibile();
    }//GEN-LAST:event_jButton3ActionPerformed


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Board b=new Board();
                b.setVisible(true);
                b.setLocation(200,200);
                b.setTitle("Gioco del 15 - by Paolo Ricciuti (C)");
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

}
